<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="/js/jquery-3.5.0.min.js" type="text/javascript"></script>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/components.css">
    <link rel="stylesheet" href="/css/login.css">
    <title>创建商品</title>
</head>
<body class="login">
<div class="content">
    <h3>创建商品</h3>
    <div>
        <label class="control-label" for="title">商品名称</label>
        <div>
            <input class="form-control" type="text" name="title" id="title">
        </div>
        <label class="control-label" for="description">商品描述</label>
        <div>
            <input class="form-control" type="text" name="description" id="description">
        </div>
        <label class="control-label" for="price">价格</label>
        <div>
            <input class="form-control" type="text" name="price" id="price">
        </div>
        <label class="control-label" for="stock">库存数量</label>
        <div>
            <input class="form-control" type="text" name="stock" id="stock">
        </div>
        <label class="control-label" for="imgUrl">图片链接</label>
        <div>
            <input class="form-control" type="text" name="imgUrl" id="imgUrl">
        </div>
        <div class="form-actions">
            <button class="btn red-thunderbird" type="submit" id="create">点击创建</button>
        </div>
    </div>
</div>


</body>
<script>
    $(function () {
        $("#create").on("click", function () {
            $.ajax({
                type: "POST",
                url: "/item/create_item",
                data: {
                    "title": $("#title").val(),
                    "price": $("#price").val(),
                    "description": $("#description").val(),
                    "imgUrl": $("#imgUrl").val(),
                    "stock": $("#stock").val()
                },
                success: function (data) {
                    if (data.status === "success") {
                        alert("商品创建成功");
                        window.Location="item_list.html"
                    } else {
                        alert("商品创建失败：" + data.data.errorMsg);
                    }
                },
                error: function (data) {
                    alert("商品创建失败！" + data.responseText)
                }
            })
        })
    })
</script>
</html>